package cn.zdm.demo.config.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * copyright (C), 2021, 武大吉奥科技有限公司
 *
 * @Program demo
 * @Description
 * @Author ZhaoDeman
 * @Create 2021/3/1 20:35
 * @Version 1.0.0
 * <author>                <time>                  <version>                   <description>
 * ZhaoDeman        2021/3/1 20:35                 1.0
 */
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        //关联
        template.setConnectionFactory(factory);
        //设置key的序列化器
        template.setKeySerializer(new StringRedisSerializer());
        //设置value的序列化器
        template.setValueSerializer(new JdkSerializationRedisSerializer());
        //设置hash
        template.setHashKeySerializer(new StringRedisSerializer());
        //设置hash序列化器
        template.setHashValueSerializer(new JdkSerializationRedisSerializer());
        return template;
    }
}

